package com.spider.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.sql.*;

//@Component
//@Slf4j
public class JdbcUtilV5 {

    private static final String JDBC_URL = "jdbc:mysql://223.4.24.90:3306/altadb?useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true";
    private static final String USER = "kingdee";
    private static final String PASSWORD = "forkingdee";

    static {
        try {
            Class.forName("com.mysql.jdbc.Driver"); // MySQL 5.x 驱动类名
            //log.info("成功加载 MySQL5 驱动");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("加载MySQL驱动失败", e);
        }
    }

    public static Connection getConnection() throws SQLException {
        return DriverManager.getConnection(JDBC_URL, USER, PASSWORD);
    }

    public static void close(Connection conn, Statement stmt, ResultSet rs) {
        try {
            if (rs != null) rs.close();
            if (stmt != null) stmt.close();
            if (conn != null) conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
